package com.nwpu.am.pojo.dto;


import com.nwpu.am.annotation.Role;
import com.nwpu.am.annotation.Sex;
import com.nwpu.am.pojo.entity.User;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Date;


/**
 * UserAddDTO
 *
 * @author Du
 * @version 1.0
 * {@code @date} 2024/6/4
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("用户添加信息传输对象")
public class UserAddDTO implements Serializable {
    @NotEmpty(message = "用户名不能为空")
    private String username;
    @NotEmpty(message = "密码不能为空")
    private String password;
    @Pattern(regexp = "^\\d{11}$", message = "要求电话号码为11位数字")
    @ApiModelProperty("电话号码为11位数字")
    private String phoneNum;
    @Email(message = "邮箱格式必须规范")
    private String email;
    @Sex
    @ApiModelProperty("性别为0（男）或1（女）或2（未知）")
    private short sex;
    private String address;
    private Date birthday;
    @Role
    @ApiModelProperty("角色为0（维修人员）或1（管理人员）")
    private short role;

    /**
     * 转为User
     *
     * @return User
     */
    public User toUser(){
        return new User(0, this.username, this.password, this.phoneNum, this.email, this.sex, this.address, this.birthday, this.role );
    }
}
